#include <iostream>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <algorithm>
#define int long long
using namespace std;

void solve()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = ' ' + s;
    vector<int>days;
    days.push_back(0);
    int tmp = 0;
    for(int i = 1; i <= n; i ++)
    {
        if(s[i] == '1')
        {
            tmp ++;
        }
        else if(s[i] == '0' && tmp != 0)
        {
            days.push_back(tmp);
            tmp = 0;
        }
    }
    if(tmp) 
    {
        days.push_back(tmp);
        tmp = 0;
    }
    int day = 0x3f3f3f3f;
    if(s[1] == '1' && s[n] != '1')
    {
        day = days[1] - 1;
        for(int i = 2; i < days.size(); i ++)
        {
            if(days[i] % 2 == 1) day = min((int)((int)days[i] / 2 + (days[i] % 2 == 0 ? 0 : 1)),day);
            else day = min(day,(days[i] - 2) / 2);
        }
    }
    if(s[1] != '1' && s[n] == '1')
    {
        day = days[days.size() - 1] - 1;
        for(int i = 1; i < days.size() - 1; i ++)
        {
            if(days[i] % 2 == 1) day = min((int)((int)days[i] / 2 + (days[i] % 2 == 0 ? 0 : 1)),day);
            else day = min(day,(days[i] - 2) / 2);
        }
    }
    if(s[1] == '1' && s[n] == '1')
    {
        day = days[days.size() - 1] - 1;
        day = min(day,days[1] - 1);
        for(int i = 2; i < days.size() - 1; i ++)
        {
            if(days[i] % 2 == 1) day = min((int)((int)days[i] / 2 + (days[i] % 2 == 0 ? 0 : 1)),day);
            else day = min(day,(days[i] - 2) / 2);
        }
    }
    if(day == 0)
    {
        int ans = 0;
        for(int i = 1; i <= n; i ++)
        {
            if(s[i] == '1') ans++;
        }
        cout << ans << endl;
        return;
    }
    int ans = 0;
    for(int i = 1; i <= days.size() - 1; i ++)
    {
        if(days[i]%(day*2+1)==0) ans+=days[i]/(day*2+1);//不能整除要上取整
        else ans+=(int)(days[i]*1.0/(day*2+1)+1);
    }
    cout << ans << endl;
}

signed main()
{
    int t = 1;
    //cin >> t;
    while(t --)
    {
        solve();
    }
}
